package com.example.erp.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.erp.domain.DataResult;
import com.example.erp.log.TokenRequired;
import com.example.erp.utils.JwtHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 18481
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private JwtHelper jwtHelper;

    @PostMapping("/login")
    @TokenRequired(value = false)
    public DataResult<JSONObject> login(String loginName, String password) throws Exception {
        Map<String, Object> claims = new HashMap<String, Object>();
        claims.put("id", 1);
        return DataResult.success(jwtHelper.generateToken(claims), JSONObject.class);
//        if ("1".equals(password)) {
//            return DataResult.success(jwtHelper.generateToken(claims).toString(), String.class);
//        } else {
//            return DataResult.faild(ErpErrorCode.USERNAME_PASSWORD_FAILED.getErrorCode(), ErpErrorCode.USERNAME_PASSWORD_FAILED.getErrorReason());
//        }
    }


}
